//
//  Star.cpp
//  popstar
//
//  Created by luyuhuang on 14/11/29.
//
//

#include "Star.h"


Star* Star::create(StarColor color)
{
    Star* star = new Star();
    
    std::string file = star->getStarfile(color);
    
    if (star &&  star->initWithFile(file)) {
        star->autorelease();
        
        star->setColor(color);
        
        return star;
        
        
    } else {
        
        delete  star;
        
        star = nullptr;
        
    }
    
    return nullptr;
}



std::string Star::getStarfile(int color)
{
    switch (color) {
        case RED:
            return "red.png";
            break;
        case GREEN:
            return "green.png";
            break;    
        case YELLOW:
            return "orange.png";
            break;
         case PURPLE:
            return "purple.png";
            break;
        default:
            break;
    }
    
    return "";
}



bool Star::init()
{
    _isSelected = false;
    _indexPath = {0,0};
    _destPosition = {0,0};
    
    return true;
}


void Star::updatePosition()
{
    
    if (this->getPosition().x > _destPosition.x ) {
        this->setPositionX(this->getPosition().x - Star::MOVE_SPEED);
    }
    
    if (this->getPosition().y > _destPosition.y) {
        this->setPositionY(this->getPosition().y - Star::MOVE_SPEED);
    }
    
    
}

Star::Star()
{
    init();
}


Star::~Star()
{
    
    
}

